package com.power.algorithm.sort;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/5/21 3:43 下午
 * 冒泡排序
 */
public class BubbleSort {
    static int[] array5 = Tools.createOrigin5Array();
    static int[] array100 = Tools.createOrigin5Array();

    public static void main(String[] args) {

        int[] originArray = new BubbleSort().sort(array5);
        Tools.display(originArray);
    }


    public int[] sort(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1; j++) {
                if (array[j] > array[j + 1]) {
                    // int tmp = array[j + 1];
                    //array[j++] = array[j];
                    //array[j] = tmp;
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
        //Arrays.stream(arr).forEach(e -> System.out.println(e));
        return array;
    }


    /*public static void main(String[] args) {
        int[] array = new int[]{2, 1, 3, 5, 4};

        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1; j++) {
                if (array[j] > array[j + 1]) {
                   // int tmp = array[j + 1];
                    //array[j++] = array[j];
                    //array[j] = tmp;
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }

    }*/
}
